#!/bin/sh
cd ${0%/*} || exit 1    # run from this directory

# Source tutorial run functions
. $WM_PROJECT_DIR/bin/tools/RunFunctions

# copy propeller surface from resources folder
cp $FOAM_TUTORIALS/resources/geometry/propellerTip.obj.gz constant/triSurface/


# - meshing

runApplication blockMesh

surfaces="
    innerCylinder
    innerCylinderSmall
    outerCylinder
    propellerTip
    propellerStem1
    propellerStem2
    propellerStem3
"

for s in $surfaces; do
    runApplication surfaceFeatureExtract -includedAngle 150 -minElem 10        \
        constant/triSurface/$s.obj $s
    mv log.surfaceFeatureExtract log.surfaceFeatureExtract.$s
done

runApplication snappyHexMesh -overwrite


# - generate face/cell sets and zones

#runApplication setSet -batch removeRedundantZones.setSet
#mv log.setSet log.removeRedundantZones.setSet
runApplication topoSet -dict system/removeRedundantZones.topoSetDict
mv log.topoSet log.removeRedundantZones.topoSet

#runApplication setSet -batch createInletOutletSets.setSet
#mv log.setSet log.createInletOutletSets.setSet
runApplication topoSet -dict system/createInletOutletSets.topoSetDict
mv log.topoSet log.createInletOutletSets.topoSet

#runApplication setSet -batch createAMIFaces.setSet
#mv log.setSet log.createAMIFaces.setSet
runApplication topoSet -dict system/createAMIFaces.topoSetDict
mv log.topoSet log.createAMIFaces.topoSet


# - create the inlet/outlet patches

runApplication createPatch -overwrite


# force removal of fields generated by snappy
\rm -rf 0

createBaffles -internalFacesOnly -overwrite innerCylinderSmall '(AMI1 AMI2)'   \
    > log.createBaffles 2>&1

runApplication mergeOrSplitBaffles -split -overwrite


# - apply the initial fields

cp -rf 0.org 0
